<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>点餐系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <link rel="stylesheet" href="/css/app.css?v19"/>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript" src="/js/jquery.fly.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/json2.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="/js/common.js?v8"></script>
    <script type="text/javascript" src="/js/SPA.js?v25"></script>
    <script type="text/javascript" src="/js/Cart.js?v12"></script>
</head>
<body class="wx">

<div class="page-container">

</div>
<script th:inline="javascript">

    window.OrderState = {
        confirmed: 0, //已确认订单
        wechat_payed: 1, //已通过微信支付的订单
        unconfirmed: 2, // 为确认订单
        cart_message: 3, // 购物车信息
        scan_qr_payed: 4, // 扫描
        offline_payed: 5,
        refused: 6
    }

    var isWaiter = false;
    if(isWaiter){
        $(document.body).removeClass('wx');
    }

    var key = $.cookie('appkey');
    $.removeCookie('appkey');

    var userId=$.cookie(key + '_uid');
    window.userId = userId;//'ohmygod';//测试使用
    window.storeId = $.cookie('cookie_store_id');
    window.isWaiter = isWaiter;
    //window.tableId = $.cookie('bindtabid');
    window.tableId =0;

    cart.storeId(window.storeId);
    cart.userId(window.userId);
    cart.tableId(window.tableId);
    window.initCart = function(){
        console.log('initCart');
        cart.clear();
        cart.userId(window.userId);
        cart.storeId(window.storeId);
        cart.tableId(window.tableId);
    };

    (function () {

        /**
         * 手机端，点击效果补丁
         */
        function phonePatch(){
            $(document).on('touchstart',function(e){});
            $(document).on('touchend',function(e){});
        }


        var cartOrderId = $.cookie("cartOrderId"); //读取提交到服务器的购物车订单id
        var hascart = $.cookie("hascart");
        if(hascart!="1" && cartOrderId){
            console.log('clear local cart');
            //1.执行删除本地购物车数据
            initCart();
            //2.删除hascart的cookie
            $.removeCookie('hascart',{'path':'/'})
            //3.删除cartOrderId 的cookie
            $.removeCookie('cartOrderId',{'path':'/'})
        }

        phonePatch();
        var spa = new SPA();
        window.spa = spa;
        if(isWaiter){
            spa.setOptions({index:'/snippet/tables.html'});
        }else{
            spa.setOptions({
                index:'/snippet/menus.html',
                order:'/snippet/preview.html' //订单列表
            });
        }

        spa.start();

    }());
</script>
</body>
</html>